/*
go实现进程namespace隔离
*/


func main()  {
    cmd := exec.Command("/bin/sh")
    cmd.SysProcAttr = &syscall.SysProcAttr{
        Cloneflags: syscall.CLONE_NEWNET,   //创建新的net  namespace
    }
    cmd.Stdin  = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr

    if err := cmd.Run(); err != nil {
        log.Printf("Run error:%v\n", err)
        log.Fatal(err)
    }
}

func main()  {
    cmd := exec.Command("/bin/sh")
    cmd.SysProcAttr = &syscall.SysProcAttr{
        Cloneflags: syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWNS | syscall.CLONE_NEWNET | syscall.CLONE_NEWIPC,
    }
    cmd.Stdout  = os.Stdout
    cmd.Stdin   = os.Stdin
    cmd.Stderr  = os.Stderr

    if err := cmd.Run(); err != nil {
        log.Fatal(err)
    }
}

/*
    syscall.CLONE_NEWIPC                     = 0x8000000
    syscall.CLONE_NEWNET                     = 0x40000000
    syscall.CLONE_NEWNS                      = 0x20000    创建新的mnt namespace
    syscall.CLONE_NEWPID                     = 0x20000000
    syscall.CLONE_NEWUSER                    = 0x10000000
    syscall.CLONE_NEWUTS                     = 0x4000000
*/